home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / tools / dupsrcs.c < prev    next >
C/C++ Source or Header  |  1991-11-07  |  2KB  |  84 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/dir.h>
  4. #include <sys/stat.h>
  5. #include <sys/errno.h>
  6. #include <sys/param.h>
  7.  
  8. /* Duplicates a source tree. */
  9.  
  10. /* $Header: dupsrcs.c,v 1.2 91/11/07 22:55:36 wlott Exp $ */
  11.  
  12. void duptree(srcdir, dstdir)
  13. char *srcdir, *dstdir;
  14. {
  15.     DIR *dir;
  16.     struct direct *entry;
  17.     char srcpath[MAXPATHLEN], dstpath[MAXPATHLEN];
  18.     struct stat buf;
  19.  
  20.     printf("Duplicating %s\n  into %s\n", srcdir, dstdir);
  21.  
  22.     /* Make sure the dstdir is there. */
  23.     if (mkdir(dstdir) == 0)
  24.     printf("Creating %s\n", dstdir);
  25.  
  26.     dir = opendir(srcdir);
  27.     if (dir == NULL) {
  28.     perror(srcdir);
  29.     return;
  30.     }
  31.  
  32.     while ((entry = readdir(dir)) != NULL) {
  33.     if (strncmp(entry->d_name, "RCS", 3) == 0)
  34.         continue;
  35.     if (entry->d_name[0] == '.')
  36.         continue;
  37.     sprintf(srcpath, "%s/%s", srcdir, entry->d_name);
  38.     sprintf(dstpath, "%s/%s", dstdir, entry->d_name);
  39.     if (stat(srcpath, &buf) < 0) {
  40.         perror(srcpath);
  41.         continue;
  42.     }
  43.     if ((buf.st_mode & S_IFMT) == S_IFDIR)
  44.         duptree(srcpath, dstpath);
  45.     else
  46.         if (symlink(srcpath, dstpath) == 0)
  47.         printf("Linked %s\n", dstpath);
  48.         else
  49.         if (errno != EEXIST)
  50.             perror(dstpath);
  51.     }
  52.  
  53.     closedir(dir);
  54. }
  55.  
  56. main(argc, argv)
  57. int argc;
  58. char *argv[];
  59. {
  60.     char *subdir;
  61.     char srcdir[MAXPATHLEN], dstdir[MAXPATHLEN];
  62.  
  63.     if (argc > 2) {
  64.     fprintf(stderr, "usage: dupsrcs [ subdir ]\n");
  65.     exit(1);
  66.     }
  67.  
  68.     if (argc == 2)
  69.     subdir = argv[1];
  70.     else
  71.     subdir = "alpha";
  72.  
  73.     getwd(dstdir);
  74.  
  75.     sprintf(srcdir, "/afs/cs/project/clisp/src/%s", subdir);
  76.     if (chdir(srcdir) < 0) {
  77.     perror(srcdir);
  78.     exit(1);
  79.     }
  80.     getwd(srcdir);
  81.  
  82.     duptree(srcdir, dstdir);
  83. }
  84.